package userlogic

import (
	"context"
	"github.com/jinzhu/copier"
	"zhongxc.cc/admin-common/errs"
	userdomain "zhongxc.cc/admin-user/internal/domain/user"
	"zhongxc.cc/admin-user/internal/model"
	"zhongxc.cc/admin-user/internal/svc"
	"zhongxc.cc/grpc-common/admin-user/types/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type InfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
	sysUserDomain *userdomain.SysUserDomain
}

func NewInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoLogic {
	return &InfoLogic{
		ctx:           ctx,
		svcCtx:        svcCtx,
		Logger:        logx.WithContext(ctx),
		sysUserDomain: userdomain.NewSysUserDomain(svcCtx.Db),
	}
}

func (l *InfoLogic) Info(in *user.UserInfoReq) (userInfo *user.UserInfoRes, err error) {
	// todo: add your logic here and delete this line
	userId := in.UserId
	sysUser, err := l.sysUserDomain.FindById(context.Background(), userId)
	if err != nil {
		return nil, errs.GrpcError(model.ErrorQueryFail)
	}

	userInfos := user.UserInfoRes{}

	if sysUser != nil {
		_ = copier.Copy(&userInfos, &sysUser)
	}
	return &userInfos, nil
}
